from __future__ import annotations

from dataclasses import dataclass


@dataclass
class ScaffoldLoad:
    design_axial_kN: float
    design_horizontal_kN: float
    note: str


def design_scaffold_load(
    deck_load_kN_m2: float = 2.0,
    self_weight_kN_m: float = 0.35,
    bay_length_m: float = 1.5,
    bay_width_m: float = 1.2,
    lift_interval_m: float = 1.8,
    wind_pressure_kPa: float = 0.3,
) -> ScaffoldLoad:
    """扣件式钢管脚手架立杆轴力与水平力估算。

    - 立杆分担面积：A = L × W / 4
    - 竖向：N ≈ (楼板施工荷载×A + 自重×层高) × 1.2
    - 水平：H ≈ w × 迎风宽度 × 层高 / 拉结间距
    参数参考 JGJ 130 经验值，供初步设计使用。
    """

    influence_area = (bay_length_m * bay_width_m) / 4.0
    vertical = (deck_load_kN_m2 * influence_area + self_weight_kN_m * lift_interval_m) * 1.2
    horizontal = wind_pressure_kPa * bay_width_m * lift_interval_m / max(1e-6, bay_length_m)
    return ScaffoldLoad(design_axial_kN=vertical, design_horizontal_kN=horizontal, note="需按构造与稳定详细复核")


@dataclass
class MemberCheck:
    slenderness: float
    capacity_ok: bool
    note: str


def check_vertical_member(
    effective_length_m: float,
    radius_of_gyration_m: float,
    axial_kN: float,
    design_capacity_kN: float,
    slenderness_limit: float = 150.0,
) -> MemberCheck:
    """立杆长细比与承载力校核。"""

    slenderness = effective_length_m / max(1e-6, radius_of_gyration_m)
    ok = slenderness <= slenderness_limit and axial_kN <= design_capacity_kN
    note = "通过" if ok else "不通过"
    return MemberCheck(slenderness=slenderness, capacity_ok=ok, note=note)


